package myjava;

import javax.swing.plaf.IconUIResource;

public class Main {

    public static void main(String[] args) {
	// write your code here

    //    equal_and_tostring();

     //       test_trafic_light();

        test_drwa();
    }



    public static void equal_and_tostring(){
        //**********************************************************学习 重写equal 与toString（）***********
        // *****************************************函数部分******************
        People p1 =new People(1,"tom");
        People p2 = new People(1,"tm");
        People p4 = new People(2,"tm");
        Object p3 = new Object();
        System.out.println("p1=p4"+p1.equals(p4));
    }



   public static void test_trafic_light(){
       //**********************************************************学习 多态与继承***********
       // *****************************************函数部分******************
       light_controll t =new light_controll();
        t.light(new red_light());

   }

   public static void test_drwa(){
        Square s =new Square(); //定义一个正方形
       s.draw(); //调用接口，draw接口在class Squre中被重新覆盖
       s.doAnything(); //调用父类Quadrangle的方法

       Parallelogram p =new Parallelogram();
       p.draw();
       p.doAnything();

       Circular c= new Circular();
       c.draw();
   }



}

class People {
    /**********************************************************学习 重写equal 与toString（）***********
     * *****************************************class部分******************

     */
    int id;
    String name;

    public People (int id, String name){
        this.id = id;
        this.name=name;
    }

    public boolean equals(Object obj) {
        if (this == obj) { //判断自己比较自己x
            System.out.println("if (this == obj) is called!");
        return true;
    }
        if (obj == null)
            return  false;
        if (getClass() != obj.getClass()) {
            System.out.println("i(getClass() != obj.getClass()) is called!");
            return false;
        }
        System.out.println("obj="+obj);
        People p= (People) obj;
        //System.out.println("People p= (People) obj;="+obj);
        if (id != p.id) {
            System.out.println("if (id != p.id)is called!");
            return false;
        }

        return true;

    }

    public  String toString(){
        return name;
    }







}




//**********************************************************学习 多态与继承***********
// *****************************************class******************
// 以多态方式呈现红绿灯时间，p127 训练14
class trafic_light{} //创建一个交通信号灯类
class red_light extends trafic_light{}  //红灯继承 交通信号灯类
class yellow_light extends trafic_light{}
class green_light extends trafic_light{}

class light_controll{
    public static void light(trafic_light l){
        if (l instanceof  red_light) //多态判断
            System.out.println("red_light is 45s");
        if (l instanceof yellow_light)
            System.out.println("yellow_light is 5s");
        if (l instanceof green_light)
            System.out.println("green_light is 30s");
    }
}


//**********************************************************学习 抽象类与接口***********
//p129 例7.13将图形对象的绘图方法剥离出来，作为Paintable可绘制接口中的抽象方法。创建四边形类作为平行四边形、正方形类，并实现Paintable接口；创建圆形类实现Paintable接口。

interface Paintable{
    public void draw();

}

class Quadrangle{
    public void doAnything(){
        System.out.println("四边形方法is called");
    }
}

class Parallelogram extends Quadrangle implements Paintable{
    public void draw(){
        System.out.println("平行四边形方法is called");
    }
}
class Square extends Quadrangle implements Paintable{
    public void draw(){
        System.out.println("正方形方法is called");
    }
}
class Circular implements Paintable{
    public void draw(){
        System.out.println("圆形方法is called");
    }
}
